<script setup>
import { ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import api from '@/api'

const $route = useRoute()
const $router = useRouter()

const pageVal = ref(1)
const pageSize = ref(10)
const listTotal = ref(0)
const listData = ref([])
const getListData = async (page) => {
  try {
    const res = await api.get('/evaluate/evaluatePlanList', {
      params: {
        page,
        pageSize: pageSize.value,
      },
    })
    console.log('res', res)
    listData.value = res.data.items
    listTotal.value = res.data.pageInfo.total
    pageVal.value = page
  } catch (error) {
    console.error(error)
  }
}
getListData(1)

const toJump = (url) => {
  console.log('router', $router.push(url))
  $router.push(url)
}
</script>

<template>
  <div class="page">
    <div class="header">
      <a-button @click="toJump('/evaluate/addPlans')"
                type="primary">创建评价计划</a-button>
    </div>

    <a-table :data="listData"
             @page-change="getListData"
             :pagination="{
              showTotal: true,
              size: 'small',
              total: listTotal,
              pageSize: pageSize,
              current: pageVal,
            }">
      <template #columns>
        <a-table-column title="序号"
                        :width="60">
          <template #cell="{ rowIndex }"> {{ rowIndex + 1 }} </template>
        </a-table-column>
        <a-table-column title="评价计划名称"
                        data-index="plan_name"></a-table-column>
        <a-table-column title="所属部门"
                        data-index="departments"></a-table-column>
        <a-table-column title="岗位名称"
                        data-index="posts"></a-table-column>
        <a-table-column title="评价人数"
                        data-index="recruit_number"></a-table-column>
        <a-table-column title="剩余人数"
                        data-index="residue_number"></a-table-column>
        <a-table-column title="当前节点"
                        data-index="status">
          <template #cell="{ record }">
            <template v-if="record.status==0">未开始</template>
            <template v-if="record.status==1">进行中</template>
            <template v-if="record.status==2">评价完成</template>
          </template>
        </a-table-column>
        <a-table-column title="操作"
                        align="center"
                        :width="88">
          <template #cell="{ record }">
            <a-space>
              <a-button type="primary"
                        size="mini"
                        @click="toJump('/evaluate/plansDetails?id=' + record.id)">查看详情</a-button>
            </a-space>
          </template>
        </a-table-column>
      </template>
    </a-table>
  </div>
</template>

<style scoped>
.page {
  height: 95%;
}

.header {
  height: 52px;
  display: flex;
}
</style>
